//
//  NormalProblemTableViewCell.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/19.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "NormalProblemTableViewCell.h"
#import "TriangleView.h"

@interface NormalProblemTableViewCell()
@property (nonatomic, strong)UIImageView * grayBGView;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)UIView * lineView;
@property (nonatomic, strong)TriangleView * triangleView;//画三角
@end

@implementation NormalProblemTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.grayBGView];
        [self.grayBGView addSubview:self.contentLab];
        [self.contentView addSubview:self.lineView];
    }return self;
}

+ (CGFloat)heightForCellWithComment:(NSDictionary *) model{
    return [self contentLabelHeight:model[@"content"]] + 40/WIDTH_6_SCALE ;
}

+ (CGFloat)contentLabelHeight:(NSString *) text{
    CGRect rectToFit = [text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 64/WIDTH_6_SCALE, MAXFLOAT)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0f]}
                                          context:nil];
    return rectToFit.size.height;
}

- (UIImageView *)grayBGView{
    if (!_grayBGView) {
        _grayBGView = [[UIImageView alloc] init];
        _grayBGView.backgroundColor = getColor(@"f5f5f5");
    }return _grayBGView;
}
- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = DEF_FontSize_13;
        _contentLab.textColor = [UIColor blackColor];
        _contentLab.textAlignment = NSTextAlignmentLeft;
    }return _contentLab;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = getColor(@"efefef");
    }return _lineView;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    //三角
    CGPoint piont1;
    piont1.x = 29/WIDTH_6_SCALE;
    piont1.y = 7/WIDTH_6_SCALE;
    CGPoint piont2;
    piont2.x = 24/WIDTH_6_SCALE;
    piont2.y = 13/WIDTH_6_SCALE;
    CGPoint piont3;
    piont3.x = 35/WIDTH_6_SCALE;
    piont3.y = 13/WIDTH_6_SCALE;
    self.triangleView = [[TriangleView alloc]initStartPoint:piont1 middlePoint:piont2 endPoint:piont3 color:getColor(@"f5f5f5")];
    self.triangleView.frame = CGRectMake(0, 1/WIDTH_6_SCALE, SCREEN_WIDTH, 13/WIDTH_6_SCALE);
    self.triangleView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.triangleView];
    //灰色背景
    self.grayBGView.frame = CGRectMake(17/WIDTH_6_SCALE, self.triangleView.bottom, SCREEN_WIDTH - 34/WIDTH_6_SCALE, [[self class] contentLabelHeight:self.model[@"content"]] + 22/WIDTH_6_SCALE);
    //具体内容
    self.contentLab.frame = CGRectMake(10/WIDTH_6_SCALE, 0 + 10/WIDTH_6_SCALE, self.grayBGView.width - 30/WIDTH_6_SCALE, [[self class] contentLabelHeight:self.model[@"content"]]);
    self.contentLab.backgroundColor = [UIColor redColor];
    //分割线
    self.lineView.frame = CGRectMake(18/WIDTH_6_SCALE, self.contentView.bottom - 1/WIDTH_6_SCALE, SCREEN_WIDTH - 18/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.contentLab.text = model[@"content"];
}
@end
